#ifndef MYAUDIO_H_INCLUDED
#define MYAUDIO_H_INCLUDED

#include "SDL/SDL_mixer.h"
#include <string>
#include <iostream>
#include <list>

using namespace std;

class Sound_effect
{
    public:
        Mix_Chunk *sound;
        SDL_Thread *sound_effect_thread;


        Sound_effect()
        {
            sound = NULL;
            sound_effect_thread = NULL;
        }

        ~Sound_effect()
        {
            Mix_FreeChunk( sound );
            SDL_WaitThread( sound_effect_thread, NULL );
        }

        void load_sound( string file_name )
        {
            sound = Mix_LoadWAV( file_name.c_str() );
            if( NULL == sound )
            {
                cout << "error loading sound file (panic plz)\n";
            }
        }

        static int start_once_thread( void *data )
        {
            ((Sound_effect*)data)->play_once();
        }

        void play_once()
        {
            //Mix_PlayChannelTimed( -1, sound, 0, 500 );
            Mix_PlayChannel( -1, sound, 0 );
        }

        static int start_loop_thread( void *data )
        {
            ((Sound_effect*)data)->play_loop();
        }

        void play_loop()
        {
            Mix_PlayChannel( -1, sound, -1 );
        }
};

class MyAudio
{

    private:
        Sound_effect *main_music;

        list< Sound_effect * > sound_effect_list;

        bool has_a_music_thread;

        int clear_sounds;

    public:
        MyAudio();
        ~MyAudio();

        static void callback_start( int channel );

        void clear_effect_data( list< Sound_effect * > tmp );
        void clear_effect_data();

        void create_audio_thread( string file_name, string option );

};

#endif // MYAUDIO_H_INCLUDED
